package studydome;

public class arrChange {
    //定义一个方法
    // 1/将数组arr中从索引from （包含from)开始，到索引to结束（不包含to）的
    public static void main(String[] args){
        //创建数组
        int[] arr= {1,2,3,4,5,6,7,8,9};

        //引用方法
        int[] newarr = copyArr(arr, 3, 6);

        //遍历新数组
        for (int i = 0; i < newarr.length; i++) {
            System.out.print(newarr[i] + " ");
        }

    }
    //将数组arr中从索引from （包含from)开始，到索引to结束（不包含to）的
    public static int[] copyArr(int[] arr,int from, int to){
        //定义新数组的长度
        int[] newarr = new int[ to - from];

        //伪造索引的思想
        int index = 0;
        for (int i = from; i < to; i++) {
            newarr[index] =arr[i];
            index++;
        }
        return newarr;
    }
}
